/*---------------------------------------------------------------------------
//
//	Copyright(C) SMIT Corporation, 2000-2010.
//
//  File	:	sm_trace.h
//	Purpose	:	
//	History :
//				2004-09-10 created by pmy.
//
---------------------------------------------------------------------------*/
 
#ifndef __SM_TRACE_H
#define __SM_TRACE_H

#include "os.h"


#ifdef __cplusplus
extern "C"{
#endif

void diag_printf_bytes(const unsigned char* buf, unsigned long size, const char *fmt, ...);
void virtualTrace(unsigned long mod, const char*, ...);
void virtualTraceBytes(unsigned long mod, unsigned long level, const unsigned char* buf,
						unsigned long size,const char *fmt, ...);

enum	//trace module ids
{
	TRMOD_ITC,
	TRMOD_PHY,	
	TRMOD_CI,
	TRMOD_DRV,
	TRMOD_TRANS,
	TRMOD_LINK,
	TRMOD_SESS,	
	TRMOD_APP,	
	TRMOD_KAPI,
	TRMOD_EXTINT,

	TRMOD_MMI,
	TRMOD_CAS,
	TRMOD_HC,
	TRMOD_SAS,
	TRMOD_RESERVED2,
	TRMOD_RESERVED3,
	TRMOD_RESERVED4,
	TRMOD_RESERVED5,
	TRMOD_RESERVED6,
	TRMOD_RESERVED7,
	TRMOD_RESERVED8,
	TRMOD_RESERVED9,
	
	TRMOD_USR0,
	TRMOD_USR1,
	TRMOD_USR2,
	TRMOD_USR3,
	TRMOD_USR4,
	TRMOD_USR5,
	TRMOD_USR6,
	TRMOD_USR7,
	TRMOD_USR8,
	TRMOD_USR9,
	TRMOD_COUNT,
};

enum //trace level
{
	TRLEV_NONE  	= 0,
	TRLEV_CRITICAL	= 2,
	TRLEV_ERROR		= 4,
	TRLEV_NOTIFY	= 6,	
	TRLEV_INFO		= 8,
	TRLEV_CALL		= 10,
};


#define _DEBUG


#ifdef _DEBUG
	void diag_printf_speclev(unsigned long mod, unsigned long level, const char *fmt, ...);
	void diag_printf_bytes_speclev(unsigned long mod, unsigned long level, 
									const unsigned char* buf,
									unsigned long size,const char *fmt, ...);
	void diag_printf_critical(unsigned long mod, const char *fmt, ...);
	void diag_printf_error(unsigned long mod, const char *fmt, ...);
	void diag_printf_notify(unsigned long mod, const char *fmt, ...);
	void diag_printf_info(unsigned long mod, const char *fmt, ...);
	void diag_printf_call(unsigned long mod, const char *fmt, ...);
	unsigned long sm_trace_set_level(unsigned long mod, unsigned long level);
	void SetTraceFilename(const char* filename);

	#ifndef TRACE_ALL_ENABLE
		#define TRACE_ALL_ENABLE	1
	#endif
	
	#if TRACE_ALL_ENABLE
		#undef TRACE_ERROR_ENABLE
		#undef TRACE_NOTIFY_ENABLE
		#undef TRACE_INFO_ENABLE
		#undef TRACE_CALL_ENABLE
		#define TRACE_ERROR_ENABLE		1	
		#define TRACE_NOTIFY_ENABLE		1		
		#define TRACE_INFO_ENABLE		1		
		#define TRACE_CALL_ENABLE		1
	#endif //TRACE_ALL_ENABLE
	
	#define SM_TRACE_SET_LEVEL	sm_trace_set_level
	#define SM_TRACE  diag_printf_speclev
	#define SM_TRACE_BYTES 	diag_printf_bytes_speclev	
	
	#define SM_TRACE_CRITICAL diag_printf_critical

	#if TRACE_ERROR_ENABLE
		#define SM_TRACE_ERROR		diag_printf_error
	#else
		#define SM_TRACE_ERROR   1 ? (void)0 : virtualTrace
	#endif

	#if TRACE_NOTIFY_ENABLE
		#define SM_TRACE_NOTIFY		diag_printf_notify
	#else
		#define SM_TRACE_NOTIFY	   1 ? (void)0 : virtualTrace
	#endif

	#if TRACE_INFO_ENABLE
		#define SM_TRACE_INFO		diag_printf_info
	#else
		#define SM_TRACE_INFO	   1 ? (void)0 : virtualTrace
	#endif

	#if TRACE_CALL_ENABLE
		#define SM_TRACE_ENTRY	diag_printf_call
		#define SM_TRACE_RETURN	diag_printf_call
	#else
		#define SM_TRACE_ENTRY   1 ? (void)0 : virtualTrace
		#define SM_TRACE_RETURN   1 ? (void)0 : virtualTrace
	#endif

#define SM_ASSERT(expression) {if (!expression){SM_Printf("ASSERT:%s %d\r\n",__FILE__,__LINE__);while(1);}}

#else	//!_DEBUG
	void virtual_diag_printf_speclev(unsigned long mod, unsigned long level, const char *fmt, ...);
	#define SM_TRACE_SET_LEVEL(mod, level)
	#define SM_TRACE  1 ? (void)0 : virtual_diag_printf_speclev
	#define SM_TRACE_BYTES 1 ? (void)0 : virtualTraceBytes
	#define SM_TRACE_CRITICAL   1 ? (void)0 : virtualTrace
	#define SM_TRACE_ERROR   1 ? (void)0 : virtualTrace
	#define SM_TRACE_NOTIFY	   1 ? (void)0 : virtualTrace
	#define SM_TRACE_INFO	   1 ? (void)0 : virtualTrace
	#define SM_TRACE_ENTRY   1 ? (void)0 : virtualTrace
	#define SM_TRACE_RETURN   1 ? (void)0 : virtualTrace
	#define SM_ASSERT(expression)
#endif // end !_DEBUG


#ifdef __cplusplus
}
#endif

#endif // __SM_TRACE_H
